define(function __form(require) {
    var $ = require("zepto");
    var global = require("global");
    var page = require("page");
    var form = {
        signUpCheck_input: function ($container, $label) {
            var _is = true;
            var $input = $container.find("input");
            return $input.each(function () {
                if ("" !== this.name && "undefined" !== this.name) {
                    var name = this.name;
                    var holder = $(this).attr("placeHolder");
                    var func = form.regFunction(name, holder);
                    var empty_tip = func.empty_tip;
                    var reg = func.reg;
                    var reg_tip = func.reg_tip;
                    if ("" === $.trim($(this).val())) {
                        return form.showCheckMessage($label, empty_tip, false);
                        $(this).addClass("z-error");
                        _is = false;
                    }
                    if (void 0 !== reg && "" !== reg && !$(this).val().match(reg)) {
                        return $(this).addClass("z-error");
                        form.showCheckMessage($label, reg_tip, false);
                        _is = false;
                    }
                    $(this).removeClass("z-error");
                    $(".u-note-error").html("");
                    $label.html("");
                }
            });
            _is ? false : true;
        },
        regFunction: function (t, n) {
            var tip = "";
            var msg = "";
            var reg = "";
            var r = false;
            t.indexOf("new") > -1 ? r = !0 : n = null;
            var s = $("#activity_id").val();
            switch (t) {
                case"name":
                    reg = /^[\u4e00-\u9fa5|a-z|A-Z|\s]{1,20}$/;
                    tip = "不能落下姓名哦！";
                    msg = "这名字太怪了！";
                    break;
                case"sex":
                    tip = "想想，该怎么称呼您呢？", msg = "";
                    break;
                case"tel":
                    reg = /^1[0-9][0-9]\d{8}$/, tip = "有个联系方式，就更好了！", msg = "这号码,可打不通... ";
                    break;
                case"email":
                    reg = 4111 != s ? /(^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$)/i : /^[\u4e00-\u9fa5|a-z|A-Z|\s|\d]{1,20}$/, tip = "都21世纪了，应该有个电子邮箱吧！", msg = "邮箱格式有问题哦！";
                    break;
                case"company":
                    reg = /^[\u4e00-\u9fa5|a-z|A-Z|\s|\d]{1,20}$/, tip = "填个公司吧！", msg = "这个公司太奇怪了！";
                    break;
                case"job":
                    reg = /^[\u4e00-\u9fa5|a-z|A-Z|\s]{1,20}$/, tip = "请您填个职位", msg = "这个职位太奇怪了！";
                    break;
                case"date":
                    tip = "给个日期吧！", msg = "";
                    break;
                case"time":
                    tip = "填下具体时间更好哦！", msg = "";
                    break;
                case"new1":
                case"new2":
                case"new3":
                case"new4":
                case"new5":
                    reg = /^.*$/, tip = r ? "请填写" + n : "", msg = "";
                    break;
                case"age":
                    reg = /^([3-9])|([1-9][0-9])|([1][0-3][0-9])$/, tip = "有个年龄就更好了！", msg = "这年龄可不对哦！"
            }
            return{empty_tip: tip, reg_tip: msg, reg: reg};
        },
        signUpCheck_submit: function (t, o) {
            global.loadingPageShow($(".u-pageLoading"));
            var url = "/auto/submit/" + $("#activity_id").val();
            $.ajax({
                url: url,
                cache: false,
                dataType: "json",
                async: true,
                type: "POST",
                data: t.serialize(),
                success: function (t) {
                    global.loadingPageHide($(".u-pageLoading"));
                    if (200 === t.code) {
                        form.showCheckMessage($(".u-note"), $(".u-note-sucess").data("type"), !0);
                        setTimeout(function () {
                            $(".book-form").removeClass("z-show");
                            $(".book-bg").removeClass("z-show");
                            setTimeout(function () {
                                $(document.body).css("height", "100%");
                                page.page_start();
                                global._scrollStop();
                                $(".book-bg").addClass("f-hide");
                                $(".book-form").addClass("f-hide");
                            }, 500);
                        }, 3e3);
                        $(".book-bd .bd-form .btn").addClass("z-stop");
                        $(".book-bd .bd-form .btn").attr("data-submit", "true");
                    } else if (400 === t.code) {
                        form.showCheckMessage($(".u-note"), $(".u-note-error").data("type"), false);
                    }
                },
                error: function (t, i, r) {
                    form.showCheckMessage(o, r, false);
                    setTimeout(function () {
                        global.loadingPageHide($(".u-pageLoading"));
                    }, 500);
                }});
        },
        showCheckMessage: function (note, type, mode) {
            if (mode) {
                $(".u-note-sucess").html(type);
                $(".u-note-sucess").addClass("on");
                $(".u-note-error").removeClass("on");
                setTimeout(function () {
                    $(".u-note").removeClass("on");
                }, 2e3);
            } else {
                $(".u-note-error").html(type);
                $(".u-note-error").addClass("on");
                $(".u-note-sucess").removeClass("on");
                setTimeout(function () {
                    $(".u-note").removeClass("on");
                }, 2e3);
            }
        }};
    return form;
});
